home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
clang
/
nn.zip
/
NN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-12-31
|
11KB
|
544 lines
/*
* The User Interface main program
*/
#include "config.h"
#include "menu.h"
#include "term.h"
#include "keymap.h"
#include "options.h"
static int
dont_read_init_file = 0,
prompt_for_group = 0;
static char
*match_subject = NULL;
export int
article_limit = -1,
also_read_articles = 0,
conf_auto_quit = 0,
do_kill_handling = 1,
group_name_args = 0,
merged_menu = 0,
silent = 0,
Debug = 0;
import int
keep_rc_backup, no_update, /* rc.c */
preview_window, fmt_linenum, fmt_rptsubj, /* menu.c */
show_article_date, first_page_lines, /* more.c */
dont_split_digests, dont_sort_articles, /* group.c */
dont_sort_folders, /* folder.c */
also_unsub_groups, /* sequence.c*/
show_current_time, conf_dont_sleep; /* term.c */
Option_Description(nn_options) {
'a', Int_Option(article_limit),
'B', Bool_Option(keep_rc_backup),
'd', Bool_Option(dont_split_digests),
'f', Bool_Option(dont_sort_folders),
'g', Bool_Option(prompt_for_group),
'I', Bool_Option(dont_read_init_file),
'k', Bool_Option(do_kill_handling),
'l', Int_Option(first_page_lines),
'L', Int_Option_Optional(fmt_linenum, 3),
'm', Bool_Option(merged_menu),
'N', Bool_Option(no_update),
'q', Bool_Option(dont_sort_articles),
'Q', Bool_Option(silent),
's', String_Option(match_subject),
'S', Bool_Option(fmt_rptsubj),
'T', Bool_Option(show_current_time),
'w', Int_Option_Optional(preview_window, 5),
'W', Bool_Option(conf_dont_sleep),
'x', Int_Option_Optional(also_read_articles, -1),
'X', Bool_Option(also_unsub_groups),
'Z', Int_Option(Debug),
'\0',
};
static int
report_number_of_articles = 0,
report_group_names = 0;
static char
*check_message_format = NULL;
Option_Description(check_options) {
'Q', Bool_Option(silent),
'r', Bool_Option(report_number_of_articles),
'f', String_Option(check_message_format),
't', Bool_Option(report_group_names),
'\0',
};
/* program name == argv[0] without path */
char *pname;
main(argc, argv)
int argc;
char *argv[];
{
extern long unread_articles;
extern char *program_name();
int emacs_slave_mode = 0, check_news = 0, enter_admin_mode = 0;
int who_am_i = 0;
pname = program_name(argv);
if (strcmp(pname, "nnadmin") == 0) {
who_am_i = 2;
enter_admin_mode = 1;
} else
if (strcmp(pname, "nnemacs") == 0)
emacs_slave_mode = 1;
else
if (strcmp(pname, "nncheck") == 0) {
who_am_i = 3;
keep_rc_backup = 0;
check_news = 1;
}
if (!check_news && !emacs_slave_mode && (!enter_admin_mode || argc == 1))
if (!isatty(0)) {
fprintf(stderr, "Input is not a tty\n");
nn_exit(1);
}
if (init_global(who_am_i) < 0) {
fprintf(stderr, "%s: nn has not been invoked to initialize user files\n", pname);
nn_exit(1);
}
init_key_map();
init_execute();
init_macro();
open_master(OPEN_READ);
#ifdef NNTP
nntp_check();
#endif
if (enter_admin_mode) {
visit_active_file();
if (argc == 1) {
init_term();
visit_init_file(0);
}
admin_mode(argv[1]);
nn_exit(0);
}
if (check_news) {
group_name_args =
parse_options(argc, argv, (char *)NULL, check_options, " [group | [+]folder]...");
visit_init_file(1);
} else
if (!emacs_slave_mode) {
init_term();
if (argc < 2 || strncmp(argv[1], "-I", 2))
visit_init_file(0);
group_name_args =
parse_options(argc, argv, (char *)NULL,
nn_options, " [group | [+]folder]...");
if (!silent)
print_version("Release %R.%V.%P #%U, Kim F. Storm, 1989\n\n");
}
if (also_read_articles) {
if (article_limit < 0)
article_limit = also_read_articles;
do_kill_handling = 0;
no_update++;
}
if (match_subject) {
if (*match_subject != '/') init_quick_match(match_subject);
no_update++;
do_kill_handling = 0;
}
if (merged_menu) {
no_update++;
}
if (!no_update && group_name_args > 0)
no_update = only_folder_args(argv + 1);
visit_rc_file();
if (group_name_args > 0)
named_group_sequence(argv + 1);
else
normal_group_sequence();
count_unread_articles(report_group_names);
if (emacs_slave_mode)
prt_unread("%U %G\n");
if (check_news) {
if (check_message_format) {
if (unread_articles || !silent)
prt_unread(check_message_format);
} else
if (report_number_of_articles) {
prt_unread("%U");
nn_exit(0);
} else
if (!silent) {
if (unread_articles || report_number_of_articles)
prt_unread("There %i %u in %g\n");
else
prt_unread((char *)NULL);
}
nn_exit( unread_articles ? 0 : 99 );
}
if (unread_articles == 0 &&
group_name_args == 0 &&
!also_read_articles &&
!prompt_for_group) {
if (!silent) prt_unread((char *)NULL);
nn_exit(0);
}
if (do_kill_handling)
do_kill_handling = init_kill();
if (emacs_slave_mode) {
emacs_mode();
goto out;
}
if (prompt_for_group) {
printf("\r\n\n");
raw();
current_group = NULL;
prompt_line = Lines - 3;
goto_group(K_GOTO_GROUP, (article_header *)NULL);
no_raw();
clrdisp();
goto out;
}
if (!no_update && article_limit == 0) {
char answer[50];
prt_unread("\nCatch-up on %u ? (all) (i)nteractive ");
fl;
if (gets(answer)) {
if (strncmp(answer, "all", 3) == 0) {
printf("\nUPDATING rc FILE....");
fl;
read_news(-1);
printf("DONE\n");
goto out;
}
if (*answer == 'i') {
read_news(1);
goto out;
}
}
printf("\nNO UPDATE\n");
goto out;
}
if (merged_menu) {
merge_and_read(match_subject, do_kill_handling);
clrdisp();
} else
if (read_news(0)) {
clrdisp();
} else {
gotoxy(0,Lines-1);
if (group_name_args == 0)
printf("No News\n");
else
printf("\r\n");
}
#ifdef STATISTICS
log_usage();
#endif
if (!also_read_articles && unread_articles > 0 && !silent && group_name_args == 0)
prt_unread("There %i still %u in %g\n\n\r");
out:
nn_exit(0);
/*NOTREACHED*/
}
/*
* nn_exit() --- called whenever a program exits.
*/
nn_exit(n)
{
static int loop = 0;
if (loop) exit(n);
loop++;
unset_raw();
visual_off();
#ifdef NNTP
nntp_cleanup();
#endif /* NNTP */
close_master();
close_rc();
exit(n);
}
export group_header *jump_to_group = NULL;
static read_news(mode)
{
register group_header *cur, *prev, *tmp, *after_loop;
int menu_cmd;
int must_clear = 0, did_jump = 0;
extern int menu();
prev = group_sequence;
cur = group_sequence;
after_loop = NULL;
while (cur != NULL || did_jump || conf_auto_quit) {
if (s_hangup) break;
if (mode == 0 && cur == NULL) {
if (after_loop != NULL) {
cur = after_loop;
after_loop = NULL;
cur->last_article = cur->first_article;
continue;
}
if (did_jump) {
did_jump = 0;
cur = group_sequence;
continue;
}
if (!must_clear) return 0;
prompt("\1LAST GROUP READ. QUIT NOW?\1");
switch (yes(1)) {
case 1:
return 1;
case 0:
cur = group_sequence;
default:
after_loop = prev;
continue;
}
}
if (!also_read_articles)
if (cur->last_article >= cur->last_l_article) {
cur = cur->next_group;
continue;
}
if (mode) {
if (mode > 0) {
char answer[50];
printf("Update %s (%ld)? ",
cur->group_name,
(long)(cur->last_l_article - cur->last_article));
fl;
if (gets(answer) == NULL || s_keyboard) {
putchar(NL);
printf("Update rest? ");
fl;
if (gets(answer) == NULL || *answer != 'y')
return 0;
mode = -1;
*answer = 'y';
}
if (*answer == '?') {
printf("Enter (y)es to update current group\n");
continue; /* redo current group */
}
if (*answer != 'y') {
cur = cur->next_group;
continue;
}
}
update_rc(cur);
continue;
}
free_memory();
if (cur->group_flag & G_FOLDER) {
menu_cmd = folder_menu(cur->group_name);
if (menu_cmd == ME_NO_REDRAW) {
menu_cmd = ME_NO_ARTICLES;
cur->last_l_article = 0;
}
} else
menu_cmd = group_menu(cur, (article_number)(-1),
match_subject, do_kill_handling, menu);
if (menu_cmd != ME_NO_ARTICLES) {
after_loop = NULL;
must_clear++;
}
switch (menu_cmd) {
case ME_PREV:
tmp = cur;
cur = prev;
prev = tmp;
cur->last_article = cur->first_article;
continue;
case ME_READ:
cur->last_article = cur->last_l_article;
/* fall thru */
case ME_NEXT:
prev = cur;
/* fall thru */
case ME_NO_ARTICLES:
cur = cur->next_group;
continue;
case ME_QUIT:
if (jump_to_group) {
prev = cur;
cur = jump_to_group;
jump_to_group = NULL;
did_jump = 1;
continue;
}
return must_clear;
}
}
return must_clear;
}
export char *mail_box = NULL;
unread_mail(t)
time_t t;
{
struct stat st;
static time_t next = 0;
static int any = 0;
if (next > t) return any;
next = t + 60;
any = 0;
if (mail_box == NULL ||
stat(mail_box, &st) != 0 ||
st.st_size == 0 ||
st.st_mtime < st.st_atime) return 0;
any = 1;
return 1;
}
#ifdef STATISTICS
static time_t usage_time = 0;
tick_usage(end_t, start_t)
time_t *end_t, *start_t;
{
time_t temp_t;
static time_t last_t = 0;
if (end_t == NULL) end_t = &temp_t;
time(end_t);
if (start_t == 0) {
/*
* We ignore delays > 2 minutes because the user has probably
* just left the terminal inside nn and done something else
*/
if ((last_t + 120) > *end_t)
usage_time += *end_t - last_t;
} else
usage_time += (*end_t - *start_t)/60;
last_t = *end_t;
}
log_usage()
{
usage_time /= 60;
if (usage_time < STATISTICS) return; /* don't log short sessions */
log_entry('U', "USAGE %d.%02d", usage_time/60, usage_time%60);
}
#endif
#ifdef MALLOC_TEST
static int in_calloc = 0;
char *malloc(n)
unsigned int n;
{
char *p, *sbrk();
if (p = sbrk(n + 3))
while ( ((int)p) & 3) p++;
if (!in_calloc)
printf("MALLOC(%u) => %lx\n", n, (long)p);
return p;
}
char *calloc(n, s)
unsigned n, s;
{
char *p;
in_calloc = 1;
p = malloc(n*s);
in_calloc = 0;
printf("CALLOC(%u,%u) => %lx\n", n, s, (long)p);
return p;
}
free(p)
char *p;
{
printf("FREE(%lx)\n", p);
}
char *realloc()
{
printf("REALLOC\n");
}
#endif /* MALLOC_TEST */
/* this will go into emacs_mode.c when it is completed someday */
emacs_mode()
{
printf("EMACS MODE IS NOT SUPPORTED YET.\n");
}